<template>
    <div>
        <el-dialog v-model="props.visible" title="人员列表" width="70%" @close="handleCancel">
            <el-form :model="queryParams" ref="queryRef" :inline="true">
                <el-row>
                    <el-form-item label="员工编号" prop="code">
                        <el-input v-model="queryParams.code" placeholder="请输入员工编号" @keyup.enter="handleQuery" />
                    </el-form-item>
                    <el-form-item label="员工名称" prop="name">
                        <el-input v-model="queryParams.name" placeholder="请输入员工名称" @keyup.enter="handleQuery" />
                    </el-form-item>
                    <el-form-item label="手机号码" prop="telephone">
                        <el-input v-model="queryParams.telephone" placeholder="请输入员工手机号码" @keyup.enter="handleQuery" />
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                    </el-form-item>
                </el-row>

            </el-form>
            <el-table v-loading="loading" :data="userList" stripe border style="cursor: pointer;"
                @cell-click="handleCellClick">
                <el-table-column label="序号" type="index" align="center" />
                <el-table-column label="员工编号" align="center" prop="code" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column label="员工名称" align="center" prop="name" :show-overflow-tooltip="true" />

                <el-table-column label="性别" align="center" prop="sex"  :show-overflow-tooltip="true">
                    <template v-slot="{ row }">
                        {{ row.sex == 1 ? "男" : "女" }}
                    </template></el-table-column>
                <el-table-column label="联系电话" align="center" prop="telephone" :show-overflow-tooltip="true">
                </el-table-column>

            </el-table>
            <div class="footer">
                <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
                    v-model:limit="queryParams.pageSize" @pagination="getList" />
            </div>
        </el-dialog>
    </div>
</template>
<script setup>
const emit = defineEmits(['changeUpdate'])
import { getMesUserInfo } from '@/api/basicInfo/personnel'
const { proxy } = getCurrentInstance();

const props = defineProps({
    visible: {
        type: Boolean,
        default: false
    },
})
watch(() => props.visible, (val) => {
    if (val) {
        handleQuery()
    }
})
const userList = ref([])
const loading = ref(false)
const queryParams = ref({
    pageNum: 1,
    pageSize: 10,
    joinPositionStatus: '1,2',
    code: undefined,
    name: undefined,
    telephone: undefined
})
const total = ref(0)
// 选中当前行
const handleCellClick = (row) => {
    proxy.$modal.confirm('是否确认选择「' + row.name + '」').then(function () {
        emit('changeUpdate', row)
    }).catch(() => { });
}

const handleCancel = () => {
    proxy.resetForm("queryRef");
    emit('cancel')
}
const getList = async () => {
    loading.value = true
    const res = await getMesUserInfo(queryParams.value)
    loading.value = false
    userList.value = res.rows
    total.value = res.total
}
// 搜索
const handleQuery = () => {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
const resetQuery = () => {
    proxy.resetForm("queryRef");
    handleQuery();
};
// getList()
</script>

<style lang="scss" scoped></style>